package com.imooc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Documentation;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    //配置Swagger2核心配置 docket

    //  http://localhost:9010/swagger-ui.html   源路径

    //  http://localhost:9010/doc.html   源路径

    @Bean
    public Docket createRestApi(){

        return  new Docket(DocumentationType.SWAGGER_2)  //SWAGGER_12 : 1.2版本 ,SWAGGER_2:2.0版本,spring-web:1.0版本
                    .apiInfo(apiInfo())              // 用于定义API文档汇总信息
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.imooc.controller"))  //指定Controller包
                    .paths(PathSelectors.any())                                         //所有 Controller
                    .build();
    }

    public ApiInfo apiInfo(){
        return  new ApiInfoBuilder()
                .title("天天吃货电商平台接口API")
                .contact(new Contact("韩东琛",
                        "https://www.imooc.com",
                        "hdc@imooc.com"))       // 联系人信息
                .description("天天吃货的API文档")
                .version("1.0")                       //文档版本号
                .termsOfServiceUrl("http://imooc.com")  //网站地址
                .build();
    }
}
